<template>
  <div>
    <div class="rate-template haruyuki-p-10" v-if="isTemplate">
      <div class="rate-template-item haruyuki-mr-20">
        <span class="rate-label" style="text-align: right;">通道名称：</span>
        <el-select size="small" v-model="aisleCodes"  placeholder="请选择 通道" @change="aisleCodesChange">
          <el-option v-for="item in aisleList" :key="item.aisleCode" :label="item.aisleName" :value="item.aisleCode">
            <span style="float: left">{{ item.aisleName }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ item.aisleCode }}</span>
          </el-option>
        </el-select>
      </div>

      <div class="rate-template-item haruyuki-mr-20">
        <span class="rate-label">签约费率：</span>
        <el-input
          size="small"
          v-model="aptTemplate.codeScanningRate"
          :precision="4"
          :step="0.0001"
          :min="0"
          :max="1"
          onkeyup="value=value.replace(/[^\d^\.]+/g,'')"
          @keyup.native="proving($event)"
        ></el-input>
        <span class="haruyuki-ml-6">%</span>
      </div>
      <div class="rate-template-item haruyuki-mr-20">
        <span class="rate-label">垫资费率：</span>
        <el-input
          size="small"
          v-model="aptTemplate.codeAdvanceRate"
          :precision="4"
          :min="0"
          :max="1"
          onkeyup="value=value.replace(/[^\d^\.]+/g,'')"
          @keyup.native="proving($event)"
        ></el-input>
        <span class="haruyuki-ml-6">%</span>
      </div>
      <el-button type="primary" size="small" plain @click="submitCover"
        >一键填入</el-button
      >
    </div>
    <div class="haruyuki-scrollbar-60vh haruyuki-p-10">
      <div
        class="haruyuki-box-hazeBlue-shadow haruyuki-mb-20"
        v-for="(dataItem, index) in data"
        :key="index"
      >
        <div
          class="
            aisle-template
            haruyuki-flex-space-between
            haruyuki-align-items-center
            haruyuki-ptb-10
            haruyuki-bg-color-hazeblue
          "
        >
          <div
            class="haruyuki-flex-center haruyuki-plr-20"
            @click="dataItem.isShow = !dataItem.isShow"
          >
            <i
              :class="
                dataItem.isShow ? 'el-icon-caret-bottom' : 'el-icon-caret-right'
              "
            ></i>
            <span class="haruyuki-size-16 haruyuki-ml-20">通道名称：</span>
            <span class="haruyuki-size-16 policy-ml-3 policy-mr-3">{{
              dataItem.aisleName
            }}</span>
          </div>
          <!-- <div class="haruyuki-mr-20" v-if="dataItem.isShowPlus === '1'">
            <span>刷卡费率(比例)：</span>
            <el-switch
              v-model="dataItem.isShowPos"
              >
            </el-switch>
          </div> -->
        </div>
        <transition name="policy">
          <div v-show="dataItem.isShow">
            <table class="haruyuki-width-100">
              <colgroup>
                <col style="width: 200px; min-width: 200px" />
                <col />
              </colgroup>
              <tbody class="ant-table-tbody">
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="0">
                  <td rowspan="2" class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">扫码</td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">扫码签约费率(比例)</td>
                  <td
                    class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue"
                    style="text-align: center"
                  >
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.codeScanningRate"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.codeScanningRate"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.codeScanningRatePlus)"
                      @change="handleInputs($event, dataItem.codeScanningRatePlus, '扫码签约费率(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低扫码签约费率(比例)为：{{ dataItem.template.codeScanningRate }}）</td>
                </tr>
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="1">
                  <!-- <td class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">扫码</td> -->
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">扫码垫资费率(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.codeAdvanceRate"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.codeAdvanceRate"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.codeAdvanceRatePlus)"
                      @change="handleInputs($event, dataItem.codeAdvanceRatePlus, '扫码垫资费率(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低扫码垫资费率(比例)为：{{ dataItem.template.codeAdvanceRate }}）</td>
                </tr>
               
                <!-- <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="6" v-if="dataItem.isShowPlus === '1' && dataItem.isShowPos"> -->
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="6" v-if="dataItem.isShowPlus === '1'">
                  <td rowspan="5" class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡</td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡贷记卡费率(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.t112Rate"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.t112Rate"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.t112RatePlus)"
                      @change="handleInputs($event, dataItem.t112RatePlus, '刷卡贷记卡费率(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低刷卡贷记卡费率(比例)为：{{ dataItem.template.t112Rate }}）</td>
                </tr>
                <!-- <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="7" v-if="dataItem.isShowPlus === '1' && dataItem.isShowPos"> -->
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="7" v-if="dataItem.isShowPlus === '1'">
                  <!-- <td class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡</td> -->
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡借记卡费率(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.t111Rate"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.t111Rate"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.t111RatePlus)"
                      @change="handleInputs($event, dataItem.t111RatePlus, '刷卡借记卡费率(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低（可设置最低刷卡借记卡费率(比例)为：{{ dataItem.template.t111Rate }}）</td>
                </tr>
                <!-- <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="8" v-if="dataItem.isShowPlus === '1' && dataItem.isShowPos"> -->
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="8" v-if="dataItem.isShowPlus === '1'">
                  <!-- <td class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡</td> -->
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡借记卡封顶(笔)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.d011RateTop"
                      :precision="2"
                      :step="0.1"
                      :min="dataItem.template.d011RateTop"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');"
                      @keyup.native="proving($event, dataItem.d011RateTopPlus)"
                      @change="handleInputs($event, dataItem.d011RateTopPlus, '刷卡借记卡封顶(笔)')"
                    ></el-input>
                    <span> 元</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低刷卡借记卡封顶(笔)为：{{ dataItem.template.d011RateTop }}）</td>
                </tr>
                <!-- <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="5" v-if="dataItem.isShowPlus === '1' && dataItem.isShowPos"> -->
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="9" v-if="dataItem.isShowPlus === '1'">
                  <!-- <td class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡</td> -->
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡贷记卡垫资费率(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.d0AdvanceDsignFee"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.d0AdvanceDsignFee"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.d0AdvanceDsignFeePlus)"
                      @change="handleInputs($event, dataItem.d0AdvanceDsignFeePlus, '刷卡贷记卡垫资费率(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低刷卡贷记卡垫资费率(比例)为：{{ dataItem.template.d0AdvanceDsignFee }}）</td>
                </tr>
                <!-- <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="5" v-if="dataItem.isShowPlus === '1' && dataItem.isShowPos"> -->
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="10" v-if="dataItem.isShowPlus === '1'">
                  <!-- <td class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡</td> -->
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">刷卡借记卡垫资费率(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.d0AdvanceJsignFee"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.d0AdvanceJsignFee"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.d0AdvanceJsignFeePlus)"
                      @change="handleInputs($event, dataItem.d0AdvanceJsignFeePlus, '刷卡借记卡垫资费率(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低刷卡借记卡垫资费率(比例)为：{{ dataItem.template.d0AdvanceJsignFee }}）</td>
                </tr>

                <!-- <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="9" v-if="dataItem.isShowPlus === '1' && dataItem.isShowPos"> -->
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="11" v-if="dataItem.isShowPlus === '1'">
                  <td rowspan="4" class="haruyuki-bg-color-hazeblue haruyuki-border-bottom-white" style="text-align: center">云闪付</td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">云闪付优惠(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.waveRate"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.waveRate"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.waveRatePlus)"
                      @change="handleInputs($event, dataItem.waveRatePlus, '云闪付优惠(比例))')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低云闪付优惠(比例)为：{{ dataItem.template.waveRate }}）</td>
                </tr>
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="12" v-if="dataItem.isShowPlus === '1'">
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">云闪付贷记卡大额(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.creditRate1"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.creditRate1"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.creditRate1Plus)"
                      @change="handleInputs($event, dataItem.creditRate1Plus, '云闪付贷记卡大额(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低云闪付贷记卡大额(比例)为：{{ dataItem.template.creditRate1 }}）</td>
                </tr>
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="13" v-if="dataItem.isShowPlus === '1'">
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">云闪付借记卡大额(比例)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.debitRate1"
                      :precision="4"
                      :step="0.0001"
                      :min="dataItem.template.debitRate1"
                      :max="1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');value=value.toString().match(/^\d+(?:\.\d{0,4})?/)"
                      @keyup.native="proving($event, dataItem.debitRate1Plus)"
                      @change="handleInputs($event, dataItem.debitRate1Plus, '云闪付借记卡大额(比例)')"
                    ></el-input>
                    <span> %</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低云闪付借记卡大额(比例)为：{{ dataItem.template.debitRate1 }}）</td>
                </tr>
                <tr class="haruyuki-line-height-special haruyuki-plr-40" data-row-key="14" v-if="dataItem.isShowPlus === '1'">
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-bottom-white" style="text-align: center">云闪付借记卡封顶(笔)</td>
                  <td class="haruyuki-plr-20 haruyuki-border-bottom-hazeblue" style="text-align: center">
                    <el-input
                      class="haruyuki-width-50"
                      size="mini"
                      v-model="dataItem.debitMax1"
                      :precision="2"
                      :step="0.1"
                      :min="dataItem.template.debitMax1"
                      onkeyup="value=value.replace(/[^\d^\.]+/g,'');"
                      @keyup.native="proving($event, dataItem.debitMax1Plus)"
                      @change="handleInputs($event, dataItem.debitMax1Plus, '云闪付借记卡封顶(笔)')"
                    ></el-input>
                    <span> 元</span>
                  </td>
                  <td class="haruyuki-border-bottom-hazeblue haruyuki-border-right-hazeblue haruyuki-color-silverGray" style="text-align: center">（可设置最低云闪付借记卡封顶(笔)为：{{ dataItem.template.debitMax1 }}）</td>
                </tr>

              </tbody>
            </table>

          </div>
        </transition>
      </div>
    </div>
  </div>
</template>

<script>
import { getPolicyDetail } from "@/api/rb-service/serviceinfo/service_info";
import {
  getThirdStepVO
} from "@/api/rb-service/posinfo/pos_info";
import {
  getList,
  getDetail,
} from "@/api/rb-service/serviceTemplate/service_template";
import {
  getDetail as getEmpDetail,
  getHighestRate,
} from "@/api/rb-service/emppolicy/emp_policy";
// import { getThirdStepAttachPlus } from "@/api/rb-service/serviceinfo/service_info";

export default {
  props: {
    aisleCode: {
      type: [Number, String],
      default: "",
    },
    merchantId: {
      type: [Number, String],
      default: "",
    },
    isTemplate: {
      type: Boolean,
      default: true,
    },
    data: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      // data: [], //通道政策 树形数据
      aptTemplate: {
        codeScanningRate: 0,
        codeAdvanceRate: 0,
      },
      stateIndex: 1,
      defaultList: [
        'codeScanningRate',//扫码签约费率(比例)
        'codeAdvanceRate',//扫码垫资费率(比例)
        'd0AdvanceJsignFee',//刷卡贷记卡垫资费率(比例) 
        'd0AdvanceDsignFee',//刷卡借记卡垫资费率(比例)	
        't112Rate',//刷卡贷记卡费率(比例)
        't111Rate',//刷卡借记卡费率(比例)
        'd011RateTop',//刷卡借记卡封顶(笔)
        'waveRate',//云闪付优惠(比例)费率(比例)
      ],
      aisleList:[],
      aisleCodes:""
    };
  },
  computed: {},
  watch: {
    // data(value) {
    //   let data = value;
    //   let list = this.defaultList;
    //   for (let i = 0; i < data.length; i++) {
    //     for (const item of list) {
    //       this.handleInput(data[i][item], i, item);
    //     }
    //     // if (data[i].aisleCode === 'A0000013') {
    //     //   for (const item of list) {
    //     //     this.handleInput(data[i][item], i, item);
    //     //   }
    //     //   break;
    //     // }
    //   }
    // }
  },
  created() {
    // this.getPolicy(this.identityType);
  },
  methods: {
    /* 选择通道 */
    aisleCodesChange(e){
      if(e){
        let param ={
          aisleCode:e,
          id:this.merchantId
        }
        this.getRateInfo(param)
      }
    },
    /* 费率(比例)详情 */
    getRateInfo(param) {
      getThirdStepVO(param).then((res) => {
        if (res.data.code == "200") {
          let datas = res.data.data.vo;
          // debugger
          
          for (let i = 0; i < datas.length; i++) {
            this.$set(datas[i], "isShow", true);
            this.$set(datas[i], "templatePolNo", ""); //接口传值模板编号
            this.$set(datas[i], "templateData", ""); //已选模板数据
            this.$set(datas[i], "isShowPos", false);

            // this.$set(datas[i], "codeAdvanceRateMin", Number(resHig.data.data.codeAdvanceRate));  //配置最低可设置垫资费率(比例)
            // this.$set(datas[i], "aptRateMin", Number(resHig.data.data.aptRate));  //配置最低可设置成本费率(比例)
          }
          this.$nextTick(() => {
            this.data = JSON.parse(JSON.stringify(datas));
            if(datas[0].aisleCode){
              this.aisleCodes = datas[0].aisleCode;
            }
          });
          // this.rateForm.codeAdvanceRate = res.data.data.codeAdvanceRate;
        } else {
          this.$message({
            type: "error",
            message: res.data.message,
          });
        }
      });
    },
    /* 绑定值不能小于最低值 input */
    handleInput(value, index, key) {
      if (value*1 < this.data[index]['template'][key]*1) {
        this.data[index][key] = this.data[index]['template'][key];
      }
    },
    handleInputs(value, min, msg) {
      if (value*1 < min*1) {
        this.$message({type: "error",message: msg+'不能低于最低值'});
      }
    },
    /* input 数值检验 */
    proving(e, min) {
      var keynum = window.event ? e.keyCode : e.which;   //获取键盘码
      // var keychar = String.fromCharCode(keynum);  //获取键盘码对应的字符
      if (keynum == 189 || keynum == 109) { //禁止输入负数
        e.target.value = min || 0
      }
      // if (e.target.value.indexOf('.') == 1) { //如果值里面有’.‘的话，进去检测位小数点大于1位的话只保留一位
      //     var x = String(e.target.value).indexOf(".")+4;//得到小数点的位置
      //     var y = String(e.target.value).length - x;//小数点的位数
      //     if(y > 1){
      //         e.target.value = this.getBit(e.target.value, 4)
      //     }
      // }
      if (e.target.value.indexOf(".") != -1) {
        e.target.value = e.target.value.replace(/\.{2,}/g, '.')
        if (e.target.value.length > 6) {
          e.target.value = e.target.value.substr(0, e.target.value.length - 1)
        }
      }
      // if (e.target.value > 1) {
      //     e.target.value = 1
      // }
    },
    /* 保留小数 返回值 */
    getBit(value, bit) {
      let str = Number(value);
      str = str.toFixed(bit)
      return str;
    },
    /* 政策详情 */
    async getPolicy(type) {
      if (type === "service") {
        //查询服务商可设置最低费率(比例)
        await getHighestRate().then(async (resHig) => {
          if (resHig.data.code == "200") {
            await getPolicyDetail(
              this.oem.userNo,
              this.oem.userType,
              this.aisleCode ? this.aisleCode : ""
            ).then(async (res) => {
              if (res.data.code == "200") {
                let datas = res.data.data.aisleTradList;
                for (let i = 0; i < datas.length; i++) {
                  this.$set(datas[i], "isShow", true);
                  this.$set(datas[i], "templatePolNo", ""); //接口传值模板编号
                  this.$set(datas[i], "templateData", ""); //已选模板数据
                  this.$set(
                    datas[i],
                    "codeAdvanceRateMin",
                    Number(resHig.data.data.codeAdvanceRate)
                  ); //配置最低可设置垫资费率(比例)
                  this.$set(
                    datas[i],
                    "aptRateMin",
                    Number(resHig.data.data.aptRate)
                  ); //配置最低可设置成本费率(比例)
                  await this.templatePolicy(datas[i]);
                }
                this.$nextTick(() => {
                  this.data = JSON.parse(JSON.stringify(datas));
                });
              } else {
                this.$message({
                  type: "error",
                  message: res.data.message,
                });
              }
            });
          } else {
            this.$message({
              type: "error",
              message: resHig.data.message,
            });
          }
        });
      } else if (type === "employee") {
        await getEmpDetail(this.oem.code).then((res) => {
          if (res.data.code == "200") {
            let datas = res.data.data.aisleList;
            for (let i = 0; i < datas.length; i++) {
              this.$set(datas[i], "isShow", true);
            }
            this.$nextTick(() => {
              this.data = JSON.parse(JSON.stringify(datas));
            });
          } else {
            this.$message({
              type: "error",
              message: res.data.message,
            });
          }
        });
      }
    },
    /* 匹配政策通道编号 单模板查询 赋值 */
    async templatePolicy(data) {
      await getList("-1", "-1", { aisleCode: data.aisleCode }).then(
        (tempRes) => {
          this.$set(data, "template", tempRes.data.data.records);
          return data;
        }
      );
    },
    /* 通道政策模板 根据单通道选择模板单渲染 */
    async templateChildChange(e, index) {
      if (e.id) {
        let temp = this.data[index].template.find((item) => item.id === e.id);
        await getDetail(temp.id, this.data[index].aisleCode).then((res) => {
          let templateData = res.data.data;
          this.data[index].aptRate = templateData.aisleRateList[0].aptRate;
          this.data[index].aptScale = templateData.aisleRateList[0].aptScale;
          this.data[index].codeAdvanceRate =
            templateData.aisleRateList[0].codeAdvanceRate;
          this.data[index].templatePolNo = templateData.templatePolNo;
        });
      }
    },
    /* 通道政策模板 根据单通道选择模板单清空 */
    templateChildClear(index) {
      this.data[index].aptRate = 0;
      this.data[index].aptScale = 0;
      this.data[index].codeAdvanceRate = 0;
      (this.data[index].templateData = {}),
        (this.data[index].templatePolNo = "");
    },
    /* 结算比例change 计算最低可设置成本费率(比例) */
    changeAptScale(e, index) {
      // this.data[index].aptRate = e * this.data[index].aptRateMin;
      const decimals = e / 100;
      if (decimals * this.data[index].aptRate < this.data[index].aptRateMin) {
        this.$message({
          type: "error",
          message: "不能小于最低可设置成本费率(比例)",
        });
      }
    },
    /* 全通道政策模板 一键填入 */
    submitCover() {
      if (this.aptTemplate.codeScanningRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入签约费率(比例)",
        });
      } else if (this.aptTemplate.codeAdvanceRate == 0) {
        this.$message({
          type: "warning",
          message: "请输入垫资费率(比例)",
        });
      } else {
        for (let d = 0; d < this.data.length; d++) {
          this.data[d].codeScanningRate = this.aptTemplate.codeScanningRate;
          this.data[d].codeAdvanceRate = this.aptTemplate.codeAdvanceRate;
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.aisle-template {
  width: 100%;
  font-weight: bold;
}

.rate-template {
  display: flex;
  align-items: center;
  .rate-template-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .rate-label {
      width: 120px;
    }
  }
}

.policy-mr-3 {
  margin-right: 3px;
}

.policy-ml-3 {
  margin-left: 3px;
}

.policy-enter-active,
.policy-leave-active {
  transition: all 0.1s ease-in-out 0s;
}
.policy-enter,
.policy-leave-to {
  opacity: 0;
}
</style>